package com.glxt.repository;

import com.glxt.model.JPABean;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Optional;

public interface JPARepository extends JpaRepository<JPABean,Integer> {
    @Cacheable(cacheNames = "findById")
    Optional<JPABean> findById(int id);
    @Cacheable(cacheNames = "findByUserName")
    List findByUserName(String name);
    List<JPABean> findByuserRole(String role);
    @Query("from tbluser where userName = ?1 order by id desc")
    List<JPABean> listByName(String name);
    @Query(value = "insert into tbluser(userName,userPass,userRole) values(?1,?2,?3)",nativeQuery = true)
    @Modifying
    public int JPAInsert(String name,String pass,String role);
    @Query(value = "delete from tbluser where userName = ?1",nativeQuery = true)
    @Modifying
    public void JPADelete(String name);
    @Query(value = "update tbluser set userName = ?2 where userName = ?1",nativeQuery = true)
    @Modifying
    public void JPAUp(String name1,String name2);
}
